Router.route('/home', {
    name: 'main',
});

var requireLogin = function() {
    var openid = this.params.query.username;
    // var target = this;
    if (!openid) {
        openid = Cookie.get('zhiqid');
    }

    
    console.log(openid);
    // debugger;
    if (Meteor.user()) {
      this.next();
    }else if (openid) {
        Meteor.loginWithPassword(openid + "@qq.com", '123456', function(e) {
                if (e) {
                  console.log("登录错误。" + e);
                } else {
                  Cookie.set('zhiqid', openid, {
                      path: '/',
                      expires: 30
                  });
                }
          });
         this.next();
    }else{
      Meteor.loginWithWechat({
                loginStyle: 'redirect',
          }, function() {});
      return;
    }
    return;
}

Router.onBeforeAction(requireLogin, {
    only: 'main'
});